package com.soilflow.web.controller.reception;

import java.io.IOException;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.soilflow.common.domain.SysArticle;
import com.soilflow.common.domain.dto.SysArticleDto;
import com.soilflow.common.domain.vo.LandmarkVo;
import com.soilflow.common.domain.vo.SysArticleVo;
import com.soilflow.common.domain.vo.categoryArticleVo;
import com.soilflow.common.domain.vo.categorySearchVo;
import com.soilflow.info.mapper.SysArticleMapper;
import com.soilflow.info.service.ISysArticleService;
import com.soilflow.info.service.ISysCategoryService;
import com.soilflow.web.utils.PageUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.soilflow.common.annotation.Log;
import com.soilflow.common.core.controller.BaseController;
import com.soilflow.common.core.domain.AjaxResult;
import com.soilflow.common.enums.BusinessType;
import com.soilflow.common.utils.poi.ExcelUtil;
import com.soilflow.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 【请填写功能名称】Controller
 * 
 * @author party
 * @date 2023-10-09
 */
@RestController
@RequestMapping("/system/article")
public class SysArticleController extends BaseController {
    @Autowired
    private ISysArticleService sysArticleService;
    @Autowired
    private ISysCategoryService categoryService;
    @Resource
    private SysArticleMapper articleMapper;

    /**
     * 查询文章，并查出该文章的点赞数据、收藏数据
     */
    @GetMapping("/selectarticle")
    public TableDataInfo selectarticle(SysArticleDto sysArticle){
        startPage();
        List<SysArticle> list = sysArticleService.selectarticle(sysArticle);
        return getDataTable(list);
    }

    @GetMapping("/projectJingweidu")
    public List<LandmarkVo> projectJingweidu()
    {
        List<LandmarkVo> list = sysArticleService.projectJingweidu();
        return list;
    }

    @GetMapping("/searchArticle")
    public AjaxResult searchLand(String title) {
        return AjaxResult.success(sysArticleService.searchArticle(title));
    }
//    /**
//     * 显示热门文章，这里为点赞数量最多的文章
//     */
//    @GetMapping("/hotArticleList")
//    public TableDataInfo hotArticleList(){
//        List<SysArticleVo> list = sysArticleService.hotArticleList();
//        return getDataTable(list);
//    }

//    /**
//     * 根据分类展示最新文章
//     * @param id 分类id
//     * @return
//     */
//    @GetMapping("/categoryList")
//    public TableDataInfo categoryList(Long id){
//        System.out.println("ids = " + id);
//        List<categoryArticleVo> list = sysArticleService.categoryList(id);
//        return getDataTable(list);
//    }

//    /**
//     * 根据分类搜索文章；
//     */
//    @GetMapping("/categorySerach")
//    public categorySearchVo categorySerach(String id){
//      return sysArticleService.categorySerach(id);
//    }

    /**
     * 查询招商政策
     */
    @GetMapping("/policy")
    public TableDataInfo selectPolicy(){
        startPage();
        List<SysArticle> list = articleMapper.selectPolicy();
        return getDataTable(list);
    }


    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:article:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysArticle sysArticle)
    {
        startPage();
        List<SysArticle> list = sysArticleService.selectSysArticleList(sysArticle);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PostMapping("export1")
    public void  exportExcel1(HttpServletResponse response) throws IOException {
        sysArticleService.exportExcel1(response);
    }
    /**
     * 导入
     */
    @PostMapping("import")
    public void importExcel(MultipartFile file) throws IOException{
        sysArticleService.importExcel(file,sysArticleService,categoryService);
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:article:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysArticleService.selectSysArticleById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:article:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysArticle sysArticle)
    {
        sysArticleService.save(sysArticle);
        return success();
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:article:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysArticle sysArticle)
    {
        return toAjax(sysArticleService.updateSysArticle(sysArticle));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:article:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        System.err.println(ids);
        return toAjax(sysArticleService.deleteSysArticleByIds(ids));
    }
}
